
# FindOgre.cmake
#
# Copyright 2010 Johan Waldeback
# This file is released under GPL v3 lisence
#
#
# sets the cmake variables:
#
# Ogre_INCLUDE_DIRS
# Ogre_LIBRARY_DIRS
# Ogre_LIBRARIES
# Ogre_LIBRARIES_DEBUG
# Ogre_LIBRARY_DIRS_DEBUG
#
# set one or more environent variables to help:
# OGRE_ROOT
# OGRE_INCLUDE_DIRS
# OGRE_LIBRARY_DIRS
#

macro(OGRE_STATUS_MESSAGE _msg )
  if( NOT Ogre_FIND_QUIET )
    message(STATUS ${_msg})
endif()
endmacro()


#
# set Ogre_ROOT serach path
#
if(MSVC100)
  SET( OGRE_ROOT_SEARCH_PATH "C:/OgreSDK_vc10_v1-7-1" )
elseif(MSVC90)
  SET( OGRE_ROOT_SEARCH_PATH "C:/OgreSDK_vc9_v1-7-1" )
endif()

#
# Find Ogre_ROOT
#
find_path( Ogre_ROOT NAMES include/OGRE/Ogre.h
  PATHS
    $ENV{OGRE_ROOT}
    ${OGRE_ROOT_SEARCH_PATH}
)

SET( Ogre_FOUND TRUE)
SET( Ogre_DEBUG_FOUND TRUE )


#
# Find Ogre_INCLUDE_DIRS
#
find_path( Ogre_INCLUDE_DIRS NAMES Ogre.h
  PATHS
    $ENV{OGRE_INCLUDE_DIRS}
    ${Ogre_ROOT}/include/OGRE
)
if( NOT Ogre_INCLUDE_DIRS )
  SET( Ogre_FOUND FALSE )
  SET( Ogre_DEBUG_FOUND FALSE )
  OGRE_STATUS_MESSAGE("Ogre include dir: * NOT FOUND *")
else()
  OGRE_STATUS_MESSAGE("Ogre include dir: ${Ogre_INCLUDE_DIRS}")
endif()


#
# Find libraries
#
foreach( COMPONENT ${Ogre_FIND_COMPONENTS} )
  find_path( OGRE_${COMPONENT}_PATH NAMES release/${COMPONENT}.lib
    PATHS 
      $ENV{OGRE_LIBRARY_DIRS}
      ${Ogre_ROOT}/lib
  )
  if( "${OGRE_${COMPONENT}_PATH}" STREQUAL "OGRE_${COMPONENT}_PATH-NOTFOUND" ) 
    OGRE_STATUS_MESSAGE( "Ogre component ${COMPONENT}: * NOT FOUND *")
    SET( Ogre_FOUND FALSE )
  else()
    OGRE_STATUS_MESSAGE( "Ogre component ${COMPONENT}: ${OGRE_${COMPONENT}_PATH}")
    LIST( FIND Ogre_LIBRARY_DIRS ${OGRE_${COMPONENT}_PATH} _result )
    if( _result LESS 0 )
      SET( Ogre_LIBRARY_DIRS ${Ogre_LIBRARY_DIRS} "${OGRE_${COMPONENT}_PATH}" )
    endif()
    SET( Ogre_LIBRARY_DIRS ${Ogre_LIBRARY_DIRS} ${OGRE_LIBRARY_PATH})
    SET( Ogre_LIBRARY_DIRS_DEBUG ${Ogre_LIBRARY_DIRS} )
    SET( Ogre_LIBRARIES ${COMPONENT}.lib ${Ogre_LIBRARIES} )
    SET( Ogre_LIBRARIES_DEBUG ${COMPONENT}_d.lib ${Ogre_LIBRARIES_DEBUG} )
  endif()
endforeach()

#
# HANDLE BOOST
#
OPTION( OGRE_USE_NATIVE_BOOST "If ON, disables the Ogre version of bullet" OFF)
IF(NOT OGRE_USE_NATIVE_BOOST)
  # INCLUDE_DIR
  find_path( OgreBoost_ROOT NAMES boost/regex.hpp
    PATHS
      "$ENV{OGREBOOST_ROOT}"
      "${Ogre_ROOT}/boost_1_42"
  )

if( "${OgreBoost_ROOT}" STREQUAL "OgreBoost_ROOT-NOTFOUND" )
    OGRE_STATUS_MESSAGE("Ogre boost: * NOT FOUND *") 
    SET( Ogre_FOUND FALSE)
    SET( Ogre_DEBUG_FOUND FALSE )
  else()
    OGRE_STATUS_MESSAGE("Ogre boost: ${OgreBoost_ROOT}") 
    #INCLUDE_DIRS
    SET( Ogre_INCLUDE_DIRS ${Ogre_INCLUDE_DIRS}  ${OgreBoost_ROOT} )
    #LIBRARY_DIRS
    SET( Ogre_LIBRARY_DIRS ${Ogre_LIBRARY_DIRS} ${OgreBoost_ROOT}/lib )
    SET( Ogre_LIBRARY_DIRS_DEBUG ${Ogre_LIBRARY_DIRS_DEBUG} ${OgreBoost_ROOT}/lib )
  endif()

ENDIF()

#
# print status messages
#

#debug messages
message(STATUS "Ogre root dir: ${Ogre_ROOT}" )
message(STATUS "Ogre OIS dirs: ${OIS_INCLUDE_DIRS}" )
message(STATUS "Ogre include dirs: ${Ogre_INCLUDE_DIRS}" )
message(STATUS "Ogre library dirs: ${Ogre_LIBRARY_DIRS}" )
message(STATUS "Ogre library_debug dirs: ${Ogre_LIBRARY_DIRS_DEBUG}" )
message(STATUS "Ogre libraries: ${Ogre_LIBRARIES}" )
message(STATUS "Ogre libraries_debug: ${Ogre_LIBRARIES_DEBUG}" )


IF(Ogre_FOUND)
  if(NOT Ogre_FIND_QUIET ) 
    message(STATUS "Ogre found: ${Ogre_FOUND}")
  endif()
ELSE()
  if(Ogre_FIND_REQUIRED) 
    message(FATAL_ERROR "Ogre NOT found")
  else()
    message(STATUS "Ogre NOT found")
  endif()
ENDIF()


